import Qt 4.7

Rectangle {
    id: mainContainer

    color: "transparent"
    property alias model: listView.model

    signal callAddView;
    signal callEditView(int index);

    Component {
        id: delegate

        Rectangle {
            id: box

            x: -10;
            width: 600; height: 40
            color: "transparent"
            border { width: 1; color: Qt.lighter("gray")}

            Column {
                x: 46; y: 7

                Text {
                    text: model.modelData.description
                }
            }
            Column {
                x: 239; y: 7

                ProgressBar {
                    value: model.modelData.percentage
                }
            }
            MouseArea {
                anchors.fill: box
                onClicked: listView.currentIndex = index;
            }
        }
    }
    ListView {
        id: listView

        y: 0
        width: 523; height: 122
        orientation: ListView.Vertical
        delegate: delegate
        clip: true
        highlight: Rectangle { color: Qt.lighter("gray"); opacity: 0.5; radius: 1 }
    }
    Button {
        id: addButton

        x: 40; y: 128; width: 118; height: 52
        text: "Adicionar"

        onClicked: {
            // database-related code here
            mainContainer.callAddView();

        }
    }
    Button {
        id: editButton

        x: 201; y: 128; width: 118; height: 52
        text: "Editar"

        onClicked: {
            // database-related code here
            mainContainer.callEditView(listView.currentIndex);
        }
    }
    Button {
        id: removeButton

        x: 357; y: 128; width: 118; height: 52
        text: "Remover"

        onClicked: {
            // database-related code here
            var index = listView.currentIndex
            if (index >= 0 && index < listView.model.length)
                listView.model = daoManager.removeGoal(index);
        }
    }
}
